/*
*  Impp - Instant Messenger
*
*  Copyright (C) 2008  Oliver Schneider
*
*  This program is free software; you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation; either version 2 of the License, or
*  (at your option) any later version.
*
*  This program is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
*
*  You should have received a copy of the GNU General Public License
*  along with this program; if not, write to the Free Software
*  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/
#ifndef SRVPACKAGE_H_
#define SRVPACKAGE_H_

#include "PackageUtils.h"
#include "Flap.h"
#include "../../core/Buddy.h"
#include "Oscar.h"

namespace Impp {

class Oscar;

class SrvPackage
{
private:
	size_t pos;
	size_t size;
	byte* data;

public:
	SrvPackage(Flap & flap);
	SrvPackage(Tlv & tlv);
	SrvPackage(size_t size, byte* data);

	virtual ~SrvPackage();

	byte readByte();
	word readWord();
	word readWordLE();
	dword readDWord();
	dword readDWordLE();
	qword readQWord();
	void readString(char* str,size_t lng);
	wxString readString(size_t lng);
	byte* readData(size_t lng);
	void readArray(byte *d, size_t lng);
	void pushIn(std::vector<byte> & v, size_t lng);
	void skip(size_t lng);

	Tlv readTLV();
	Snac readSnac();
	UserInfo readUserInfos(Oscar* oscar, Buddy** buddy, wxString* statusMsg, bool* requestAvatar, Status* status);

	bool hasBytesLeft();
	size_t bytesLeft();
	void readAllocedItems(size_t anz, std::vector<Item>* out);

	void logToFile(const wxString & filename);
	void logRemainingToStdOut();
	void logToStdOut();

protected:
	void outOfBounds();

};

}

#endif /*SRVPACKAGE_H_*/
